<?php
class category_model extends jqxGrid_CI_Model {

    function __construct()
    {
        parent::__construct();
        
    }
    function get($ID){
        $where=array('id'=>$ID);
        $query=$this->db->get_where("dtb_category", $where); 
        return $query->result();
    }
    function gets(){
        $where=array('delete'=>NULL);
        $query=$this->db
                ->select("`id` as 'ID',`name` as 'Name',`alias` as 'Alias'")
                ->where("(`status`='true' or `status`='Public')")
                ->where($where)
                ->get("dtb_category"); 
        return $query->result();
    }
    function insert($params){
        $this->db->set('insert', 'NOW()', FALSE);
        $this->db->insert("dtb_category", $params); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function delete($ID){
        $this->db->set('delete', 'NOW()', FALSE);
        $where=array('id'=>$ID);
        $this->db->where($where);
        $this->db->update("dtb_category"); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function retore($ID){
        $this->db->set('delete', 'NULL', FALSE);
        $where=array('id'=>$ID);
        $this->db->where($where);
        $this->db->update("dtb_category"); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function update($ID,$params){
        $this->db->set('update', 'NOW()', FALSE);
        $this->db->where('id', $ID);
        $this->db->update("dtb_category", $params); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function binding(){
        $strQuery="
            SELECT SQL_CALC_FOUND_ROWS `id` as ID,`level` as Level,`name` as 'Name',
                `alias` as Alias,`status` as Status,`insert` as 'Insert',
                `update` as 'Update',`delete` as 'Delete'
            FROM `dtb_category`
            ";
        $strWhere="
            WHERE  true
            ";
        if($_SESSION["ADP"][CCTRL]["display"]==0){
            $strWhere.=" AND `dtb_category`.`delete` IS NULL";
        }elseif($_SESSION["ADP"][CCTRL]["display"]==-1){
            $strWhere.=" AND `dtb_category`.`delete` IS NOT NULL";
        }
        $strOrderBy="Order By dtb_category.`insert` DESC ";
        $strGroupBy="";
        $config=array(
            "strQuery"=>$strQuery,
            "strWhere"=>$strWhere,
            "strOrderBy"=>$strOrderBy,
            "strGroupBy"=>$strGroupBy,
            "usingLimit"=>false,
            "fields"=>array(
                "ID"        =>  "`id`",
                "Level"     =>  "`level`",
                "Name"      =>  "`name`",
                "Alias"     =>  "`alias`",
                "Status"    =>  "`status`",
                "Insert"    =>  "dtb_new.`insert`",
                "Update"    =>  "dtb_new.`update`",
                "Delete"    =>  "dtb_new.`delete`"
            ),
            "datefields"=>array("Insert","Update","Delete")
        );
        $this->init($config);
        return $this->jqxBinding();
    }
}
?>
